log using main-models-stata.log, replace

* Set plot scheme
set scheme plottig
graph set window fontface "LM Roman 10"
graph set print fontface "LM Roman 10"
graph set svg fontface "LM Roman 10"

* ssc install grstyle

grstyle clear
grstyle init
grstyle set plain, box
grstyle color background white

* ssc install palettes

grstyle set color Set1
grstyle yesno draw_major_hgrid yes
grstyle yesno draw_major_ygrid yes
grstyle color major_grid gs8
grstyle linepattern major_grid dot
grstyle set legend 4, box inside
grstyle color ci_area gs12%50

* Load data
use "ads_imgs_vids.dta", clear


* Reformat party family var
tab pg_party_family_name
replace pg_party_family_name = "Christian_democracy" if pg_party_family_name == "Christian democracy"
replace pg_party_family_name = "Social_democracy" if pg_party_family_name == "Social democracy"
replace pg_party_family_name = "Green_Ecologist" if pg_party_family_name == "Green/Ecologist"
replace pg_party_family_name = "Right_wing" if pg_party_family_name == "Right-wing"
replace pg_party_family_name = "Communist_Socialist" if pg_party_family_name == "Communist/Socialist"


* ##############################################################################
* MAIN MODELS
* ##############################################################################


*****************************
* 1 - DV: Any woman on image/video, Controls: Audience age, number of faces
*****************************

* Add number of ads per party
quietly logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id, difficult // Quietly run model to use same observations 
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run regression 
logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads], cluster(parlgov_id)
est store inter

* Calculate and save margins (plot in R)
margins, at(only_women = (0 1)) saving("margins.dta", replace)

* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
    quietly logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id)
	est store `g'	
}

* Output all models to latex table
outreg2 [inter Green_Ecologist  Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using 1.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)


* Calculate and save margins (plot in R)
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
   logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id)
	margins, at(only_women = (0 1) )  saving("`g'.dta", replace)
	
}



* ##############################################################################
* Robustness
* ##############################################################################


*****************************
* 2 - DV: Any woman on image, Images only, Controls: Audience age, number of faces
*****************************

* Add number of ads per party
quietly logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id if is_img == 1  // Quietly run model to use same observations 
cap drop n_ads
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run regression 
logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads] if is_img == 1, cluster(parlgov_id)
est store inter

* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
   logit faces_any_fem i.only_women c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads] if is_img == 1 & pg_party_family_name ==  "`g'", cluster(parlgov_id)
	est store `g'	
}

* Output all models to latex table
outreg2 [inter Green_Ecologist  Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using 2.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)



*****************************
* 3  DV: Any woman on image, Controls: Share of women in audience, audience age, number of faces
*****************************


* Add number of ads per party
cap drop n_ads
quietly logit faces_any_fem c.fem_audience c.audience_avg_age c.nfaces i.parlgov_id // Quietly run model to use same observations 
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run regression 
logit faces_any_fem c.fem_audience c.audience_avg_age c.nfaces i.parlgov_id [iweight=1/n_ads], cluster(parlgov_id) 
est store inter

* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
   logit faces_any_fem c.fem_audience  c.audience_avg_age  c.nfaces i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id) 
	est store `g'

}

* Output all models to latex table
outreg2 [inter Green_Ecologist Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using 3.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)


*****************************
* 4 - DV: Only women on image, Controls: Audience age, number of faces
*****************************


* Add number of ads per party
cap drop n_ads
quietly logit faces_all_fem i.only_women c.audience_avg_age  c.nfaces i.parlgov_id  // Quietly run model to use same observations 
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run regression 
logit faces_all_fem i.only_women c.audience_avg_age  c.nfaces i.parlgov_id [iweight=1/n_ads], cluster(parlgov_id) 
est store inter

* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
   logit  faces_all_fem i.only_women c.audience_avg_age  c.nfaces i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id) 
	est store `g'

}

* Output all models to latex table
outreg2 [inter Green_Ecologist Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using 4.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)


*****************************
* 5 - DV: Any woman on image, Controls: No controls
*****************************


* Add number of ads per party
cap drop n_ads
quietly logit faces_any_fem i.only_women i.parlgov_id
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run regression 
logit faces_any_fem i.only_women i.parlgov_id [iweight=1/n_ads] , cluster(parlgov_id)
est store inter


* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
	di "`g'"
    logit faces_any_fem i.only_women  i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id)
	est store `g'
	
}

* Output all models to latex table
outreg2 [inter Green_Ecologist Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using 5.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)



* ###############
* Age
* ###############

cap drop n_ads
quietly reg faces_age_mean c.audience_avg_age i.parlgov_id if is_img == 1  // Quietly run model to use same observations 
bysort parlgov_id: gen n_ads=_N if e(sample)

* Run model
reg faces_age_mean c.audience_avg_age i.parlgov_id [iweight=1/n_ads] if is_img == 1, cluster(parlgov_id)
est store inter

* Calculate margins
margins, at(audience_avg_age = (18 (5) 70) )

* Plot margins
marginsplot, xtitle("Average audience age", size(vlarge)) title(,size(vlarge)) ytitle( "Mean age on image", size(vlarge)) title("" )   plot1opts(lcolor(gs8)) ciopt(color(black%20) msize(large)) recastci(rarea) recast(line) xlabel(#5,labsize(large)) ylabel(,labsize(large)) 
graph export "marginsplot_age.pdf", replace


* Run models for each party family
levelsof pg_party_family_name if inlist(pg_party_family_name,  "Green_Ecologist","Communist_Socialist", "Social_democracy", "Christian_democracy", "Conservative", "Liberal", "Right_wing"), local(groups)
local estimates_list // 
foreach g of local groups {
    reg faces_age_mean c.audience_avg_age i.parlgov_id [iweight=1/n_ads] if pg_party_family_name ==  "`g'", cluster(parlgov_id)
    est store `g'
}

* Output all models to latex table
outreg2 [inter Green_Ecologist Communist_Socialist Social_democracy Christian_democracy Conservative Liberal Right_wing] using age.xls, replace drop(i.parlgov_id) label excel tex alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)  dec(3) e(N_clust)

log close

